package com.dx.mapper;

import com.dx.annoation.AutoSet;
import com.dx.entity.bo.Employee;
import com.dx.entity.dto.EmployeeQueryDto;
import com.dx.enums.OperationType;

import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;

@Mapper
public interface EmployeeMapper {
    //Employee字段的顺序要和数据库字段一致，否则会报数据转换错误
    //改Employee之后可能要更新下序列化Id。
    @Select("select * from employee where username=#{userName}")
    Employee getByUserName(String userName);

//    @Insert("insert into employee (name,username,password,phone,sex,id_number,status,create_time,update_time,create_user,update_user) values (#{name},#{username},#{password},#{phone},#{sex},#{idNumber},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser});")
//    @Insert("insert into address_book (id, user_id, consignee, sex, phone, province_code, province_name, city_code, city_name, district_code, district_name, detail, label, is_default) values (#{name},#);")
//    @Insert("insert into address_bookddress_book (id, user_id, consignee, sex, phone, province_code, province_name, city_code, city_name, district_code, district_name, detail, label, is_default) values ();")

    @Insert("insert into employee (name, username, email,password, phone, sex, id_number, status,create_time, update_time, create_user, update_user) values (" +
            "#{name},#{username},#{email},#{password},#{phone},#{sex},#{idNumber},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void save(Employee employee);





    @Update("update employee set status=#{status} where id=#{id}")
    boolean updateStatus(@Param("id") Long id,@Param("status") int status);

    Page<Employee> pageQuery(EmployeeQueryDto name);

    @AutoSet(OperationType.UPDATE)
    boolean update(Employee employee);

    @Select("select * from employee where email=#{email}")
    Employee getByEmail(String email);
}
